#ifndef __case_pty_kenny_kfjiweiiur89u83r33e3e__
#define __case_pty_kenny_kfjiweiiur89u83r33e3e__

#include <iostream>

#include <hude/base/log.hpp>
#include <hude/aio/context.hpp>
#include <hude/utils/pty.hpp>

#include "test/test.hpp"

namespace test
{
    using namespace hude::utils;

    //--------------------------------------------------------------------------------
    struct case_pty_t : public hude::test::case_t
    {
        // 测试过程
        bool run() override;
    };

    //--------------------------------------------------------------------------------
    inline bool case_pty_t::run()
    {
        pty_pair_t uv;

        auto cb_entry = [&]()
        {
            auto filter = []( std::vector< uint8_t >& buffer )
            {
                log_dug( "\t forward buffer{ siz: %u, hex: %s }", buffer.size(), hude::utils::to_hex( buffer ).c_str() );
            };

            auto ret = uv.bind( filter, hude::aio::context_t<>::ctx() );

            if( ret )
            {
                log_err( "error: pty_pair_t::boot() == %d", ret );
            } else {
                log_dug( "pty a{ master: %d, ptsname: %s }", uv.a().native(), uv.a().ptsname() );
                log_dug( "pty b{ master: %d, ptsname: %s }", uv.b().native(), uv.b().ptsname() );
            }
        };

        auto aio = hude::aio::context_t<>::ctx();

        auto ret = aio->run( cb_entry );

        return ret == 0;

    }

    TEST_CASE_ADD( "case-pty", case_pty_t, false );

} // namespace test

#endif // __case_pty_kenny_kfjiweiiur89u83r33e3e__

